package cc.ucanuup.config.security.util;
import java.util.concurrent.ConcurrentHashMap;

public class ValidateCodeHandle {

	private static ConcurrentHashMap<String,String> validateCode = new ConcurrentHashMap<String,String>();

	public static ConcurrentHashMap<String,String> getCode() {
		return validateCode;
	}

	public static void save(String sessionId, String code) {
		validateCode.put(sessionId, code);
	}

	public static String getValidateCode(String sessionId) {
		Object obj = validateCode.get(sessionId);
		if (obj != null) {
			return String.valueOf(obj);
		}
		return null;
	}

	/**
	 * @Method: com.bozhon.config.sercurity.util.ValidateCodeHandle.matchCode
	 * @Description:  校验二维码
	 * @author: WenBin
	 * @date: 2018年2月1日
	 * @version: 1.0
	 * @param sessionId
	 * @param inputCode
	 * @return
	 * boolean
	 * @update [日期YYYY-MM-DD] [更改人姓名][变更描述]
	 */
	public static boolean matchCode(String sessionId, String inputCode) {
		String saveCode = getValidateCode(sessionId);
		if (saveCode!=null && saveCode.toLowerCase().equals(inputCode.toLowerCase())) {
			return true;
		}
		return false;
	}

}